<#ftl ns_prefixes={"orm": "http://java.sun.com/xml/ns/persistence/orm"} 
	encoding="UTF-8" /><#recurse doc><#macro "orm:entity-mappings">
	<#global class = .node["orm:entity"].@class />
	<#global package = .node["orm:package"] />
</#macro>package ${package};

import static org.apache.commons.lang.Validate.*;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.commons.beanutils.BeanUtils;

import ${package}.${class};
import ${package}.${class}Dao;
import ${package}.${class}EditForm;
import ${package}.${class}ListForm;

import com.googlecode.horncomb.orm.support.paged.PagedList;
import com.googlecode.horncomb.orm.support.paged.PagedSetting;

/**
 * ${class} form service<br/>
 * <table>
 * <tr>
 * <td>负责人/principal:</td>
 * <td colspan="2"></td>
 * <tr>
 * <td>修改记录/revision:</td>
 * <td colspan="2"></td>
 * </tr>
 * <tr>
 * <td>日期:</td>
 * <td>修改人:</td>
 * <td>修改说明:</td>
 * </tr>
 * <tr>
 * <td></td>
 * <td></td>
 * <td></td>
 * </tr>
 * </table>
 * @author
 * @version $Id$
 */
public class ${class}FormService
{
    private ${class}Dao ${class?uncap_first}Dao;

    /**
     * ${class}列表
     * @param form
     *        表单对象
     * @return 列表页面数据
     * @throws Exception
     */
    public Map<String, Object> list(${class}ListForm form) throws Exception
    {
        Map<String, Object> ref = new HashMap<String, Object>();
        PagedSetting ps = form.getDefaultPagedSetting();
        PagedList<? extends Collection<?>> result = this.${class?uncap_first}Dao.queryAll(ps
                .getOrder(), ps.getPage(), ps.getPageSize());
        ref.put("${class?uncap_first}List", result); //$NON-NLS-1$
        ref.put("totalRows", result.getNrOfElements()); //$NON-NLS-1$
        return ref;
    }

    /**
     * 删除选中的项
     * @param form
     *        表单对象
     * @throws Exception
     */
    public void deleteItems(${class}ListForm form) throws Exception
    {
        notEmpty(form.getSelectedIds());
        Set<String> selectedItemSet = new HashSet<String>();
        selectedItemSet.addAll(form.getSelectedIds());
        this.${class?uncap_first}Dao.deleteByIds(selectedItemSet);
    }

    /**
     * 显示编辑${class}
     * @param form
     *        表单对象
     * @return 显示页面数据
     * @throws Exception
     */
    public Map<String, Object> show(${class}EditForm form) throws Exception
    {
        ${class} ${class?uncap_first} = this.${class?uncap_first}Dao.getById(form.getId());
        BeanUtils.copyProperties(form, ${class?uncap_first});

        // other reference data
        Map<String, Object> ref = new HashMap<String, Object>();
        return ref;
    }

    /**
     * 保存${class}
     * @param form
     *        表单对象
     * @throws Exception
     */
    public void save(${class}EditForm form) throws Exception
    {
        ${class} ${class?uncap_first} = this.${class?uncap_first}Dao.createNewEntity();
        BeanUtils.copyProperties(${class?uncap_first}, form);
        this.${class?uncap_first}Dao.save(${class?uncap_first});
    }

    /**
     * 删除单个${class}
     * @param form
     *        表单对象
     * @throws Exception
     */
    public void deleteItem(${class}EditForm form) throws Exception
    {
        this.${class?uncap_first}Dao.deleteById(form.getId());
    }

    /**
     * @param ${class?uncap_first}Dao
     *        the ${class?uncap_first}Dao to set
     */
    public void set${class}Dao(${class}Dao ${class?uncap_first}Dao)
    {
        this.${class?uncap_first}Dao = ${class?uncap_first}Dao;
    }
}
